﻿function BuildHeader()
{
	if (_page == "company_list")
	{
		var element;

		var regionID = "";
		element = $("#Region select:last");
		if (element.prev().length != 0 && element.val() == "")
			regionID = element.prev().val();
		else
			regionID = element.val();
		
		var includeSubRegion = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubRegion = true;
		
		var industryID = "";
		element = $("#Industry select:last");
		if (element.prev().length != 0 && element.val() == "")
			industryID = element.prev().val();
		else
			industryID = element.val();
		
		var includeSubIndustry = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubIndustry = true;
		
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&IsRecycled=" + $("#IsRecycled").val() + "&RegionID=" + regionID + "&IncludeSubRegion=" + includeSubRegion + "&IndustryID=" + industryID + "&IncludeSubIndustry=" + includeSubIndustry + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else if (_page == "person_list")
	{
		var element;

		var regionID = "";
		element = $("#Region select:last");
		if (element.prev().length != 0 && element.val() == "")
			regionID = element.prev().val();
		else
			regionID = element.val();
		
		var includeSubRegion = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubRegion = true;
		
		var industryID = "";
		element = $("#Industry select:last");
		if (element.prev().length != 0 && element.val() == "")
			industryID = element.prev().val();
		else
			industryID = element.val();
		
		var includeSubIndustry = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubIndustry = true;
		
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&IsRecycled=" + $("#IsRecycled").val() + "&RegionID=" + regionID + "&IncludeSubRegion=" + includeSubRegion + "&IndustryID=" + industryID + "&IncludeSubIndustry=" + includeSubIndustry + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else if (_page == "mail_list")
	{
		var element;

		var regionID = "";
		element = $("#Region select:last");
		if (element.prev().length != 0 && element.val() == "")
			regionID = element.prev().val();
		else
			regionID = element.val();
		
		var includeSubRegion = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubRegion = true;
		
		var industryID = "";
		element = $("#Industry select:last");
		if (element.prev().length != 0 && element.val() == "")
			industryID = element.prev().val();
		else
			industryID = element.val();
		
		var includeSubIndustry = false;
		if (element.prev().length != 0 && element.val() == "")
			includeSubIndustry = true;
		
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&IsRecycled=" + $("#IsRecycled").val() + "&RegionID=" + regionID + "&IncludeSubRegion=" + includeSubRegion + "&IndustryID=" + industryID + "&IncludeSubIndustry=" + includeSubIndustry + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else if (_page == "mail_log_list")
	{
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&ID=" + _id + "&IsSuccess=" + $("#IsSuccess").val() + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else if (_page == "mail_sender_list")
	{
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&IsRecycled=" + $("#IsRecycled").val() + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else if (_page == "tag_list")
	{
		return BuildAjaxPath(true) + "?Lang=" + _lang + "&Sort=" + $("#Sort").val() + "&Keyword=" + encodeURIComponent($("#Keyword").val()) + "&KeywordType=" + $("#KeywordType").val() + "&Page=" + _pageNumber;
	}
	else
	{
	    return BuildAjaxPath();
	}
}

function Search()
{
	if (arguments.length > 0 && typeof(arguments[0]) != "object")
		_pageNumber = arguments[0];
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : BuildHeader(),
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			var list = $("#List");

			list.html(HandleFake404(data, "text"));
			SetStatusMessage();

			if (typeof(SetupIme) == "function")
				SetupIme();
				
			if (_page == "company_list")
			{
				MakeButton();
			}
			else if (_page == "person_list")
			{
				MakeButton();
			}
			else if (_page == "mail_list")
			{
				MakeButton();
			}
			else if (_page == "mail_sender_list")
			{
				MakeButton();
			}
		}
	});
}

function MakeButton()
{
	var buttons = "";

	if (_page == "company_list")
	{
	    //回收
	    var obj = $("#IsRecycled")[0];
	    if (obj.selectedIndex == 1)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateCompany('Recycle')\" >" + _lang_recycle + "</button>";
	    }
	    else if (obj.selectedIndex == 2)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateCompany('Delete')\" >" + _lang_delete + "</button>";
		    buttons += "<button class=\"Button\" onclick=\"UpdateCompany('Recover')\" >" + _lang_recover + "</button>";
	    }
	}	
	else if (_page == "person_list")
	{
	    //回收
	    var obj = $("#IsRecycled")[0];
	    if (obj.selectedIndex == 1)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdatePerson('Recycle')\" >" + _lang_recycle + "</button>";
	    }
	    else if (obj.selectedIndex == 2)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdatePerson('Delete')\" >" + _lang_delete + "</button>";
		    buttons += "<button class=\"Button\" onclick=\"UpdatePerson('Recover')\" >" + _lang_recover + "</button>";
	    }
	}	
	else if (_page == "mail_list")
	{
	    //回收
	    var obj = $("#IsRecycled")[0];
	    if (obj.selectedIndex == 1)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateMail('Recycle')\" >" + _lang_recycle + "</button>";
	    }
	    else if (obj.selectedIndex == 2)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateMail('Delete')\" >" + _lang_delete + "</button>";
		    buttons += "<button class=\"Button\" onclick=\"UpdateMail('Recover')\" >" + _lang_recover + "</button>";
	    }
	}	
	else if (_page == "mail_sender_list")
	{
	    //回收
	    var obj = $("#IsRecycled")[0];
	    if (obj.selectedIndex == 1)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateMailSender('Recycle')\" >" + _lang_recycle + "</button>";
	    }
	    else if (obj.selectedIndex == 2)
	    {
		    buttons += "<button class=\"Button\" onclick=\"UpdateMailSender('Delete')\" >" + _lang_delete + "</button>";
		    buttons += "<button class=\"Button\" onclick=\"UpdateMailSender('Recover')\" >" + _lang_recover + "</button>";
	    }
	}	

	$("#ExtraButton").html(buttons);
}

//联动
function Linkage(element, page, callback)
{
	var me = $(element);
	me.nextAll("select").remove();
	if (me.val() == "" || me.val() == "0")
	{
		//if (callback != null)
		//	callback();
		return;
	}
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : page + "?Lang=" + _lang + "&ParentID=" + encodeURIComponent(element.value),
		type : "GET",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			SetStatusMessage();
				
			var items = eval(data);
			if (items.length == 0)
			{
				if (callback != null)
					callback();
				return;
			}

			var html = "<option value=''>" + (page.indexOf("industry") != -1 ? _lang_all_sub_industry : _lang_all_sub_region) + "</option>;";
			for (var i = 0; i < items.length; i++)
				html += "<option value='" + items[i].ID + "' InnerID='" + items[i].InnerID + "' PageGenerate='" + items[i].PageGenerate + "' PageTemplate='" + items[i].PageTemplate + "' PageID='" + items[i].PageID + "' PageExtension='" + items[i].PageExtension + "'>" + items[i].Name + "</option>";

			var next = me.next("select");
			if (next.length == 0)
			{
				html = "<select class='" + _lang + "Font'>" + html + "</select>";
				me.after(html);	
			}
			else
			{
				next.empty().append(html);			
			}

			if (callback != null)
				callback();
		}
	});	
}

function LinkageSelect(data)
{
	if (data.ParentChain == null)
	{
		$.get(data.ParentChainPage, function(result)
		{
			data.ParentChain = result;
			data.Parents = result.split(".");
			LinkageSelect(data)
		});

		return;
	}
	
	data.Element = $(data.Element);
	if (data.Parents.length == 1)
	{
		data.Element.find("[value=" + data.ID + "]").attr("selected", true);
	}
	else
	{
		data.Element.find("[InnerID=" + data.Parents[data.Index++] + "]").attr("selected", true);
		data.Element.change();
	}
}

function BindLinkageRegion()
{
	$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx", function()
	{
		if (_regionLinkageData == null)
			return;

		var last = $("#Region select:last");
		if (_regionLinkageData.Index < _regionLinkageData.Parents.length)
		{
			last.find("[InnerID=" + _regionLinkageData.Parents[_regionLinkageData.Index++] + "]").attr("selected", true);
			last.change();
		}
		else if (_regionLinkageData != null)
		{
			last.find("[value=" + _regionLinkageData.ID + "]").attr("selected", true);
			last.change();
			_regionLinkageData = null;
		}
	});}); 
}

function BindLinkageIndustry()
{
	$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx", function()
	{
		if (_industryLinkageData == null)
			return;
	
		var last = $("#Industry select:last");
		if (_industryLinkageData.Index < _industryLinkageData.Parents.length)
		{
			last.find("[InnerID=" + _industryLinkageData.Parents[_industryLinkageData.Index++] + "]").attr("selected", true);
			last.change();
		}
		else if (_industryLinkageData != null)
		{
			last.find("[value=" + _industryLinkageData.ID + "]").attr("selected", true);
			last.change();
			_industryLinkageData = null;
		}
	});}); 
}

function PrepareTag()
{
    var result = {Names:"",InnerIDs:""};
    var tags = $("[name=Tag]");
	
	if (typeof(_tagAddIndex) != "undefined")
	{
	    _tagAddIndex = 0;
	    _tagDeleteIndex = 0;
	    _tagAddList.length = 0;
	    _tagDeleteList.length = 0;
    	    	
	    tags.each(function()
	    {
		    if (this.checked)
		    {
			    var i = 0;
			    for (; i < _tags.length; i++)
			    {
				    if (this.value == _tags[i])
					    break;
			    }
			    if (i >= _tags.length)
				    _tagAddList[_tagAddList.length] = this.value;
		    }
		    else
		    {
			    for (var i = 0; i < _tags.length; i++)
			    {
				    if (this.value == _tags[i])
				    {
					    _tagDeleteList[_tagDeleteList.length] = this.value;
					    break;
				    }
			    }
		    }
	    });
	}

	_tagIndex = 0;
	_tags.length = 0;
	tags.each(function()
	{
		if (!this.checked)
		    return true;

		_tags[_tags.length] = this.value;

		if (result.Names == "")
			result.Names = "|";
		result.Names += $(this).next().text() + "|";
		
		if (result.InnerIDs == "")
			result.InnerIDs = "|";
		result.InnerIDs += this.id;
	});
	
	return result;
}

//-------------------------------------------------
//Start : 企业管理
function AddCompany()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}
	
	var tag = PrepareTag();
	data += "&TagNames=" + encodeURIComponent(tag.Names);
	data += "&TagInnerIDs=" + encodeURIComponent(tag.InnerIDs);
	
	data += "&Address=" + encodeURIComponent(this.Address.value);
	data += "&Zip=" + encodeURIComponent(this.Zip.value);
	data += "&TypeName=" + encodeURIComponent(this.TypeName.value);
	data += "&FoundedDate=" + encodeURIComponent(this.FoundedDate.value);
	data += "&LicenseNumber=" + encodeURIComponent(this.LicenseNumber.value);
	data += "&Owner=" + encodeURIComponent(this.Owner.value);
	data += "&Capital=" + encodeURIComponent(this.Capital.value);
	data += "&BusinessScope=" + encodeURIComponent(this.BusinessScope.value);
	data += "&Homepage=" + encodeURIComponent(this.Homepage.value);
	data += "&Contact=" + encodeURIComponent(this.Contact.value);
	data += "&Phone=" + encodeURIComponent(this.Phone.value);
	data += "&Mobile=" + encodeURIComponent(this.Mobile.value);
	data += "&Fax=" + encodeURIComponent(this.Fax.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&QQ=" + encodeURIComponent(this.QQ.value);
	data += "&WW=" + encodeURIComponent(this.WW.value);
	data += "&MoreContact=" + encodeURIComponent(this.MoreContact.value);
	data += "&Logo=" + encodeURIComponent(this.Logo.value);
	data += "&Staff=" + encodeURIComponent(this.Staff.value);
	data += "&Model=" + encodeURIComponent(this.Model.value);
	data += "&Description=" + encodeURIComponent(CKEDITOR.instances[this.Description.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			AddCompany_AddTag(data);
		}
	});
	
	return false;
}

function AddCompany_AddTag(guid)
{
	if (_tagIndex >= _tags.length)
	{
		Alert(_lang_operation_success);
		SetStatusMessage();
		$(":submit")[0].disabled = false;
		return;
	}
	
	var data = "CompanyID=" + guid;
	data += "&TagID=" + _tags[_tagIndex];
	
	_tagIndex++;

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company.Tag&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			AddCompany_AddTag(guid);
		}
	});
}

function EditCompany()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}
	
	var tag = PrepareTag();
	data += "&TagNames=" + encodeURIComponent(tag.Names);
	data += "&TagInnerIDs=" + encodeURIComponent(tag.InnerIDs);
	
	data += "&Address=" + encodeURIComponent(this.Address.value);
	data += "&Zip=" + encodeURIComponent(this.Zip.value);
	data += "&TypeName=" + encodeURIComponent(this.TypeName.value);
	data += "&FoundedDate=" + encodeURIComponent(this.FoundedDate.value);
	data += "&LicenseNumber=" + encodeURIComponent(this.LicenseNumber.value);
	data += "&Owner=" + encodeURIComponent(this.Owner.value);
	data += "&Capital=" + encodeURIComponent(this.Capital.value);
	data += "&BusinessScope=" + encodeURIComponent(this.BusinessScope.value);
	data += "&Homepage=" + encodeURIComponent(this.Homepage.value);
	data += "&Contact=" + encodeURIComponent(this.Contact.value);
	data += "&Phone=" + encodeURIComponent(this.Phone.value);
	data += "&Mobile=" + encodeURIComponent(this.Mobile.value);
	data += "&Fax=" + encodeURIComponent(this.Fax.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&QQ=" + encodeURIComponent(this.QQ.value);
	data += "&WW=" + encodeURIComponent(this.WW.value);
	data += "&MoreContact=" + encodeURIComponent(this.MoreContact.value);
	data += "&Logo=" + encodeURIComponent(this.Logo.value);
	data += "&Staff=" + encodeURIComponent(this.Staff.value);
	data += "&Model=" + encodeURIComponent(this.Model.value);
	data += "&Description=" + encodeURIComponent(CKEDITOR.instances[this.Description.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditCompany_DeleteTag();
		}
	});
	
	return false;	
}

function EditCompany_DeleteTag()
{
	if (_tagDeleteIndex >= _tagDeleteList.length)
	{
		EditCompany_AddTag();
		return;
	}

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company.Tag&Operation=Delete&CompanyID=" + _guid + "&TagID=" + _tagDeleteList[_tagDeleteIndex++],
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditCompany_DeleteTag();
		}
	});
}

function EditCompany_AddTag()
{
	if (_tagAddIndex >= _tagAddList.length)
	{
		Alert(_lang_operation_success);
		SetStatusMessage();
		$(":submit")[0].disabled = false;
		return;
	}
	
	var data = "CompanyID=" + _guid;
	data += "&TagID=" + _tagAddList[_tagAddIndex];
	
	_tagAddIndex++;

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company.Tag&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditCompany_AddTag();
		}
	});
}

function UpdateCompany(action, id)
{
	if (id == null)
	{
		id = "";
		$("[name=Sel]:checked").each(function(){id += id == "" ? this.value : "|" + this.value;});
		if(id == "")
		{
			Alert(_lang_selection_empty);
			return;
		}
		
		if(action == "Delete")
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)UpdateCompany(action, id);}, this);
		else
			UpdateCompany(action, id);
	}
	else
	{
		SetStatusMessage(_lang_working);

		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=" + action + "&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
			},
			success : function(data)
			{
				Alert(_lang_operation_success);
				SetStatusMessage();

				$("#List").html(HandleFake404(data, "text"));	
			}
		});
	}
}

function ReplaceCompany()
{
	if (this.From.type == "text" && this.From.value == "")
	{
		Alert(_lang_from_empty, function(){this.From.select();}, this);
		return false;
	}
	
	var data = "Property=" + this.Property.value;
	data += "&From=" + encodeURIComponent(this.From.value);
	data += "&To=" + encodeURIComponent(this.To.value);
	
	$(":submit").eq(0).attr("disabled", true);
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=Replace",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
        	$(":submit").eq(0).attr("disabled", false);
		},
		success : function(data)
		{
		    Alert(_lang_operation_success);
		    SetStatusMessage();
		    $(":submit").eq(0).attr("disabled", false);
		}
	});
	
	return false;
}

function Property_OnChange()
{
    switch (this.value)
    {
        case "RegionID":
            SetStatusMessage(_lang_working);
            $.ajax(
            {
                url : "../region/ajax_options.aspx",
                type : "GET",
                error : function(request)
                {
	                Alert(_lang_operation_fail);
	                SetStatusMessage();
                },
                success : function(data)
                {
	                _xmlDoc.loadXML(data);
	                var childNodes = _xmlDoc.documentElement.childNodes;
        			
	                var from = "<select name=\"From\" class=\"" + _lang + "Font\">" + data + "</select>";
	                var to = "<select name=\"To\" class=\"" + _lang + "Font\">" + data + "</select>";
        			
	                $("#FromTd").html(from);
	                $("#ToTd").html(to);
	                SetStatusMessage();
                }
            });
	        break;
		case "IndustryID":
            SetStatusMessage(_lang_working);
            $.ajax(
            {
                url : "../industry/ajax_options.aspx",
                type : "GET",
                error : function(request)
                {
	                Alert(_lang_operation_fail);
	                SetStatusMessage();
                },
                success : function(data)
                {
	                _xmlDoc.loadXML(data);
	                var childNodes = _xmlDoc.documentElement.childNodes;
        			
	                var from = "<select name=\"From\" class=\"" + _lang + "Font\">" + data + "</select>";
	                var to = "<select name=\"To\" class=\"" + _lang + "Font\">" + data + "</select>";
        			
	                $("#FromTd").html(from);
	                $("#ToTd").html(to);
	                SetStatusMessage();
                }
            });
	        break;
        case "Name":
        case "Description":
	        $("#FromTd").html("<input type=\"text\" name=\"From\" class=\"Text " + _lang + "Font\" />");
	        $("#ToTd").html("<input type=\"text\" name=\"To\" class=\"Text " + _lang + "Font\" />");
	        break;
        default:
	        $("#FromTd").html("<input type=\"text\" name=\"From\" size=\"40\" class=\"Text\" />");
	        $("#ToTd").html("<input type=\"text\" name=\"To\" size=\"40\" class=\"Text\" />");
	        break;
    }
}
//End : 企业管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 个人管理
function AddPerson()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}
	
	var tag = PrepareTag();
	data += "&TagNames=" + encodeURIComponent(tag.Names);
	data += "&TagInnerIDs=" + encodeURIComponent(tag.InnerIDs);
	
	data += "&Identity=" + encodeURIComponent(this.Identity.value);
	data += "&Sex=" + encodeURIComponent(this.Sex.value);
	data += "&Birthday=" + encodeURIComponent(this.Birthday.value);
	data += "&Phone=" + encodeURIComponent(this.Phone.value);
	data += "&Mobile=" + encodeURIComponent(this.Mobile.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&QQ=" + encodeURIComponent(this.QQ.value);
	data += "&Address=" + encodeURIComponent(this.Address.value);
	data += "&Zip=" + encodeURIComponent(this.Zip.value);
	data += "&Homepage=" + encodeURIComponent(this.Homepage.value);
	data += "&Profile=" + encodeURIComponent(CKEDITOR.instances[this.Profile.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			AddPerson_AddTag(data);
		}
	});
	
	return false;
}

function AddPerson_AddTag(guid)
{
	if (_tagIndex >= _tags.length)
	{
		Alert(_lang_operation_success);
		SetStatusMessage();
		$(":submit")[0].disabled = false;
		return;
	}
	
	var data = "PersonID=" + guid;
	data += "&TagID=" + _tags[_tagIndex];
	
	_tagIndex++;

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person.Tag&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			AddPerson_AddTag(guid);
		}
	});
}

function EditPerson()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}
	
	var tag = PrepareTag();
	data += "&TagNames=" + encodeURIComponent(tag.Names);
	data += "&TagInnerIDs=" + encodeURIComponent(tag.InnerIDs);
	
	data += "&Identity=" + encodeURIComponent(this.Identity.value);
	data += "&Sex=" + encodeURIComponent(this.Sex.value);
	data += "&Birthday=" + encodeURIComponent(this.Birthday.value);
	data += "&Phone=" + encodeURIComponent(this.Phone.value);
	data += "&Mobile=" + encodeURIComponent(this.Mobile.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&QQ=" + encodeURIComponent(this.QQ.value);
	data += "&Address=" + encodeURIComponent(this.Address.value);
	data += "&Zip=" + encodeURIComponent(this.Zip.value);
	data += "&Homepage=" + encodeURIComponent(this.Homepage.value);
	data += "&Profile=" + encodeURIComponent(CKEDITOR.instances[this.Profile.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditPerson_DeleteTag();
		}
	});
	
	return false;	
}

function EditPerson_DeleteTag()
{
	if (_tagDeleteIndex >= _tagDeleteList.length)
	{
		EditPerson_AddTag();
		return;
	}

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person.Tag&Operation=Delete&PersonID=" + _guid + "&TagID=" + _tagDeleteList[_tagDeleteIndex++],
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditPerson_DeleteTag();
		}
	});
}

function EditPerson_AddTag()
{
	if (_tagAddIndex >= _tagAddList.length)
	{
		Alert(_lang_operation_success);
		SetStatusMessage();
		$(":submit")[0].disabled = false;
		return;
	}
	
	var data = "PersonID=" + _guid;
	data += "&TagID=" + _tagAddList[_tagAddIndex];
	
	_tagAddIndex++;

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person.Tag&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			EditPerson_AddTag();
		}
	});
}

function UpdatePerson(action, id)
{
	if (id == null)
	{
		id = "";
		$("[name=Sel]:checked").each(function(){id += id == "" ? this.value : "|" + this.value;});
		if(id == "")
		{
			Alert(_lang_selection_empty);
			return;
		}
		
		if(action == "Delete")
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)UpdatePerson(action, id);}, this);
		else
			UpdatePerson(action, id);
	}
	else
	{
		SetStatusMessage(_lang_working);

		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Person&Operation=" + action + "&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
			},
			success : function(data)
			{
				Alert(_lang_operation_success);
				SetStatusMessage();

				$("#List").html(HandleFake404(data, "text"));	
			}
		});
	}
}
//End : 个人管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 邮件管理
function AddMail()
{
	if (this.Subject.value == "")
	{
		Alert(_lang_subject_empty, function(){this.Subject.select();}, this);
		return false;
	}
	
	if (this.Every.value == "Week" && $("#Day :checked").length == 0)
	{
		Alert(_lang_day_incorrect);
		return false;
	}

	if (!this.Interval.value.match(/^\d*$/))
	{
		Alert(_lang_interval_incorrect, function(){this.Interval.select();}, this);
		return false;
	}	
	
	var data = "Subject=" + encodeURIComponent(this.Subject.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}

	var tag = $("[name=Tag] :selected");
	data += "&TagName=" + encodeURIComponent(tag.val() == "" ? "" : tag.text());
	data += "&TagInnerID=" + encodeURIComponent(tag.val());
	
	data += "&ToCompany=" + $("#ToCompanyYes")[0].checked;

	var creator = $("[name=Creator] :selected");
	data += "&Creator=" + encodeURIComponent(creator.val() == "" ? "" : creator.text());
	data += "&CreatorID=" + encodeURIComponent(creator.val());

	data += "&Every=" + encodeURIComponent(this.Every.value);
	if (this.Every.value == "Week")
	{
		$("#Day :checked").each(function()
		{
			data += "," + this.value;
		});
	}

	if (this.Every.value != "")
		data += "&StartTime=" + FormatDate(new Date($("[name=Year]").val(), $("[name=Month]").val(), $("[name=Date]").val(), $("[name=Hour]").val(), $("[name=Minute]").val()), "YYYY-MM-DD hh:mm:ss");

	data += "&Interval=" + encodeURIComponent(this.Interval.value);
	data += "&Content=" + encodeURIComponent(CKEDITOR.instances[this.Content.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;
}

function EditMail()
{
	if (this.Subject.value == "")
	{
		Alert(_lang_subject_empty, function(){this.Subject.select();}, this);
		return false;
	}
	
	if (this.Every.value == "Week" && $("#Day :checked").length == 0)
	{
		Alert(_lang_day_incorrect);
		return false;
	}
	
	if (!this.Interval.value.match(/^\d*$/))
	{
		Alert(_lang_interval_incorrect, function(){this.Interval.select();}, this);
		return false;
	}	
	
	if (!this.LastID.value.match(/^\d+$/))
	{
		Alert(_lang_lastid_incorrect, function(){this.Subject.select();}, this);
		return false;
	}

	var data = "Subject=" + encodeURIComponent(this.Subject.value);

	var region = $("#Region [value!=]:selected:last");
	if (region.length == 1)
	{
		data += "&RegionID=" + encodeURIComponent(region.val());
		data += "&RegionName=" + encodeURIComponent(region.text());
	}
	else
	{
		data += "&RegionID=";
		data += "&RegionName=";
	}
	
	var industry = $("#Industry [value!=]:selected:last");
	if (industry.length == 1)
	{
		data += "&IndustryID=" + encodeURIComponent(industry.val());
		data += "&IndustryName=" + encodeURIComponent(industry.text());
	}
	else
	{
		data += "&IndustryID=";
		data += "&IndustryName=";
	}

	var tag = $("[name=Tag] :selected");
	data += "&TagName=" + encodeURIComponent(tag.val() == "" ? "" : tag.text());
	data += "&TagInnerID=" + encodeURIComponent(tag.val());
	
	data += "&ToCompany=" + $("#ToCompanyYes")[0].checked;

	var creator = $("[name=Creator] :selected");
	data += "&Creator=" + encodeURIComponent(creator.val() == "" ? "" : creator.text());
	data += "&CreatorID=" + encodeURIComponent(creator.val());

	data += "&Every=" + encodeURIComponent(this.Every.value);
	if (this.Every.value == "Week")
	{
		$("#Day :checked").each(function()
		{
			data += "," + this.value;
		});
	}

	if (this.Every.value != "")
		data += "&StartTime=" + FormatDate(new Date($("[name=Year]").val(), $("[name=Month]").val(), $("[name=Date]").val(), $("[name=Hour]").val(), $("[name=Minute]").val()), "YYYY-MM-DD hh:mm:ss");
	else
		data += "&StartTime=";
	data += "&Interval=" + encodeURIComponent(this.Interval.value);
	data += "&EndTime=" + encodeURIComponent(this.EndTime.value);
	data += "&LastID=" + encodeURIComponent(this.LastID.value);
	data += "&Content=" + encodeURIComponent(CKEDITOR.instances[this.Content.id].getData());
	
	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function UpdateMail(action, id)
{
	if (id == null)
	{
		id = "";
		$("[name=Sel]:checked").each(function(){id += id == "" ? this.value : "|" + this.value;});
		if(id == "")
		{
			Alert(_lang_selection_empty);
			return;
		}
		
		if(action == "Delete")
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)UpdateMail(action, id);}, this);
		else
			UpdateMail(action, id);
	}
	else
	{
		SetStatusMessage(_lang_working);

		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=" + action + "&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
			},
			success : function(data)
			{
				Alert(_lang_operation_success);
				SetStatusMessage();

				$("#List").html(HandleFake404(data, "text"));	
			}
		});
	}
}
//End : 邮件管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 邮件日志
function UpdateMailLog(action, id)
{
	if (id == null)
	{
		id = "";
		$("[name=Sel]:checked").each(function(){id += id == "" ? this.value : "|" + this.value;});
		if(id == "")
		{
			Alert(_lang_selection_empty);
			return;
		}
		
		if(action == "Delete")
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)UpdateMailLog(action, id);}, this);
		else
			UpdateMailLog(action, id);
	}
	else
	{
		SetStatusMessage(_lang_working);

		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail.Log&Operation=" + action + "&RuleID=" + _id + "&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
			},
			success : function(data)
			{
				Alert(_lang_operation_success);
				SetStatusMessage();

				$("#List").html(HandleFake404(data, "text"));	
			}
		});
	}
}

function StartExecute()
{
	var me = this;
	me.disabled = true;
	
	SetStatusMessage(_lang_start_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=StartExecute&ID=" + _id,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			me.disabled = false;
		},
		success : function(data)
		{
			setTimeout(RefreshMailLog, _interval);
		}
	});
}

function StopExecute()
{
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=StopExecute&ID=" + _id,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$("#StartExecute")[0].disabled = false;
		},
		success : function(data)
		{
			SetStatusMessage();
			$("#StartExecute")[0].disabled = false;
		}
	});
}

function RefreshMailLog()
{
	$.ajax(
	{
		url : BuildHeader(),
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
		},
		success : function(data)
		{
			var list = $("#List");
			list.html(HandleFake404(data, "text"));
			
			$.ajax(
			{
				url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Mail&Operation=IsRunning&ID=" + _id,
				data : {},
				type : "POST",
				error : function(request)
				{
					Alert(_lang_operation_fail);
				},
				success : function(data)
				{
					if (data.toLowerCase() == "true")
					{
						setTimeout(RefreshMailLog, _interval);
					}
					else
					{
						SetStatusMessage();
						$("#StartExecute")[0].disabled = false;
					}
				}
			});
		}
	});
}
//End : 邮件日志
//-------------------------------------------------

//-------------------------------------------------
//Start : 邮件发送人
function AddMailSender()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	if (this.Email.value == "")
	{
		Alert(_lang_email_empty, function(){this.Email.select();}, this);
		return false;
	}
		
	if (this.Account.value == "")
	{
		Alert(_lang_account_empty, function(){this.Account.select();}, this);
		return false;
	}
		
	if (this.Password.value == "")
	{
		Alert(_lang_password_empty, function(){this.Password.select();}, this);
		return false;
	}
		
	if (this.SMTPServer.value == "")
	{
		Alert(_lang_smtp_server_empty, function(){this.SMTPServer.select();}, this);
		return false;
	}
		
	if (!this.Port.value.match(/^\d+$/))
	{
		Alert(_lang_port_incorrect, function(){this.Port.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&Account=" + encodeURIComponent(this.Account.value);
	data += "&Password=" + encodeURIComponent(this.Password.value);
	data += "&SMTPServer=" + encodeURIComponent(this.SMTPServer.value);
	data += "&EnableSsl=" + $("#EnableSslYes")[0].checked;
	data += "&Port=" + encodeURIComponent(this.Port.value);

	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=MailSender&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function EditMailSender()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	if (this.Email.value == "")
	{
		Alert(_lang_email_empty, function(){this.Email.select();}, this);
		return false;
	}
		
	if (this.Account.value == "")
	{
		Alert(_lang_account_empty, function(){this.Account.select();}, this);
		return false;
	}
		
	if (this.SMTPServer.value == "")
	{
		Alert(_lang_smtp_server_empty, function(){this.SMTPServer.select();}, this);
		return false;
	}
		
	if (!this.Port.value.match(/^\d+$/))
	{
		Alert(_lang_port_incorrect, function(){this.Port.select();}, this);
		return false;
	}

	var data = "Name=" + encodeURIComponent(this.Name.value);
	data += "&Email=" + encodeURIComponent(this.Email.value);
	data += "&Account=" + encodeURIComponent(this.Account.value);
	if (this.Password.value != "")
		data += "&Password=" + encodeURIComponent(this.Password.value);
	data += "&SMTPServer=" + encodeURIComponent(this.SMTPServer.value);
	data += "&EnableSsl=" + $("#EnableSslYes")[0].checked;
	data += "&Port=" + encodeURIComponent(this.Port.value);

	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=MailSender&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function UpdateMailSender(action, id)
{
	if (id == null)
	{
		id = "";
		$("[name=Sel]:checked").each(function(){id += id == "" ? this.value : "|" + this.value;});
		if(id == "")
		{
			Alert(_lang_selection_empty);
			return;
		}
		
		if(action == "Delete")
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)UpdateMailSender(action, id);}, this);
		else
			UpdateMailSender(action, id);
	}
	else
	{
		SetStatusMessage(_lang_working);

		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=MailSender&Operation=" + action + "&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
			},
			success : function(data)
			{
				Alert(_lang_operation_success);
				SetStatusMessage();

				$("#List").html(HandleFake404(data, "text"));	
			}
		});
	}
}

function MoveMailSender(from, to)
{
	if (from == to)
		return;
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=MailSender&Operation=" + g_action + "&From=" + from + "&To=" + to,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			
			ClientMove(from, to, _imagePath);
		}
	});
}

function AutoSort()
{
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=MailSender&Operation=Sort&Creator=" + _creator,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
		}
	});
}
//End : 邮件发送人
//-------------------------------------------------

//-------------------------------------------------
//Start : 地区管理
function AddRegion()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var parentID = $("#Region [value!=]:selected:last");
	if (parentID.length == 0)
		parentID = $("#Region :selected:first").val();
	else
		parentID = parentID.val();
	
	var data = "ParentID=" + parentID;
	data += "&Name=" + encodeURIComponent(this.Name.value);
	if ($("#GuidCheckBox")[0].checked)
		data += "&ID=" + this.ID.value;

	$(":submit").attr("disabled", true);
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Region&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function EditRegion()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var parentID = "";
	for(var i = parseInt($("#Region select").length - 1);i >= 0 ;i --)
	{
		if($("#Region select:eq(" + i + ") option:selected").val() != "")
		{
			parentID = $("#Region select:eq(" + i + ") option:selected").val();
			break;
		}
	}
	
	var data = "ParentID=" + parentID;
	data += "&Name=" + encodeURIComponent(this.Name.value);
	if ($("#GuidCheckBox")[0].checked)
		data += "&ID=" + this.ID.value;

	$(":submit").attr("disabled", true);
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Region&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function ModifyRegion(form, id)
{
	if (form.Name.value == "")
	{
		Alert(_lang_name_empty, function(){form.Name.select();}, this);
		return;
	}
	
	form.disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Region&Operation=Modify&ID=" + id,
		data : "Name=" + encodeURIComponent(form.Name.value),
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			form.disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			form.disabled = false;
		}
	});
}

function DeleteRegion(id)
{
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Region&Operation=Delete&ID=" + id,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();

			ClientDelete(id);
		}
	});
}

function MoveRegion(from, to)
{
	if (from == to)
		return;
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Region&Operation=" + g_action + "&From=" + from + "&To=" + to,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			
			ClientMove(from, to, _imagePath);
		}
	});
}
//End : 地区管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 行业管理
function AddIndustry()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var parentID = $("#Industry [value!=]:selected:last");
	if (parentID.length == 0)
		parentID = $("#Industry :selected:first").val();
	else
		parentID = parentID.val();
	
	var data = "ParentID=" + parentID;
	data += "&Name=" + encodeURIComponent(this.Name.value);
	if ($("#GuidCheckBox")[0].checked)
		data += "&ID=" + this.ID.value;

	$(":submit").attr("disabled", true);
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Industry&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function EditIndustry()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var parentID = "";
	for(var i = parseInt($("#Industry select").length - 1);i >= 0 ;i --)
	{
		if($("#Industry select:eq(" + i + ") option:selected").val() != "")
		{
			parentID = $("#Industry select:eq(" + i + ") option:selected").val();
			break;
		}
	}
	
	var data = "ParentID=" + parentID;
	data += "&Name=" + encodeURIComponent(this.Name.value);
	if ($("#GuidCheckBox")[0].checked)
		data += "&ID=" + this.ID.value;

	$(":submit").attr("disabled", true);
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Industry&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function ModifyIndustry(form, id)
{
	if (form.Name.value == "")
	{
		Alert(_lang_name_empty, function(){form.Name.select();}, this);
		return;
	}
	
	form.disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Industry&Operation=Modify&ID=" + id,
		data : "Name=" + encodeURIComponent(form.Name.value),
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			form.disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			form.disabled = false;
		}
	});
}

function DeleteIndustry(id)
{
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Industry&Operation=Delete&ID=" + id,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();

			ClientDelete(id);
		}
	});
}

function MoveIndustry(from, to)
{
	if (from == to)
		return;
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Industry&Operation=" + g_action + "&From=" + from + "&To=" + to,
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			
			ClientMove(from, to, _imagePath);
		}
	});
}
//End : 行业管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 标签管理
function AddTag()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var data = "Name=" + encodeURIComponent(this.Name.value);

	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Tag&Operation=Add",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function ModifyTag(form, id)
{
	if (form.Name.value == "")
	{
		Alert(_lang_name_empty, function(){form.Name.select();}, this);
		return false;
	}
	
	var data = "Name=" + encodeURIComponent(form.Name.value);

	form.disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Tag&Operation=Modify&ID=" + id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function EditTag()
{
	if (this.Name.value == "")
	{
		Alert(_lang_name_empty, function(){this.Name.select();}, this);
		return false;
	}
	
	var data = "Name=" + encodeURIComponent(this.Name.value);

	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Tag&Operation=Modify&ID=" + _id,
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function DeleteTag()
{
	var id = GetChecked("Sel");
	if(id == "")
	{
		Alert(_lang_no_selection);
		return;
	}
	
	SetStatusMessage(_lang_working);

	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Tag&Operation=Delete&ID=" + id + "&Transfer=" + encodeURIComponent(BuildHeader()),
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			
			$("#List").html(HandleFake404(data, "text"));
			Init();

			if (typeof(SetupIme) == "function")
				SetupIme();			
		}
	});
}	
//End : 标签管理
//-------------------------------------------------

//-------------------------------------------------
//Start : 栏目设置
function SetBasicSettings()
{
	var data = "&Signature=" + this.Signature.value;
	if ($("#EnableCheckYes")[0].checked)
		data += "&CheckTime=" + FormatDate(new Date($("[name=Year]").val(), $("[name=Month]").val(), $("[name=Date]").val(), $("[name=Hour]").val(), $("[name=Minute]").val()), "YYYY-MM-DD hh:mm:ss");
	else
		data += "&CheckTime=";

	$(":submit")[0].disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=InstanceConfig&Operation=SetBasicSettings",
		data : data,
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			$(":submit")[0].disabled = false;
		}
	});
	
	return false;	
}

function SyncIndustry()
{
	var me = $(this);
	
	this.disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=InstanceConfig&Operation=SyncIndustry",
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			me[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			me[0].disabled = false;
		}
	});
}

function SyncRegion()
{
	var me = $(this);
	
	this.disabled = true;
	SetStatusMessage(_lang_working);
	
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=InstanceConfig&Operation=SyncRegion",
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
			SetStatusMessage();
			me[0].disabled = false;
		},
		success : function(data)
		{
			Alert(_lang_operation_success);
			SetStatusMessage();
			me[0].disabled = false;
		}
	});
}

function HandleCollect(me, start)
{
	if (typeof(start) != "string")
	{
		var me = $(this);
		Prompt(_lang_prompt, "0", function(returnValue){if (returnValue != null && returnValue != "")HandleCollect(me, returnValue);}, this);
	}
	else
	{
		this.disabled = true;
		SetStatusMessage(_lang_start_working);
		
		$.ajax(
		{
			url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=OnCollectComplete&Start=" + start,
			data : {},
			type : "POST",
			error : function(request)
			{
				Alert(_lang_operation_fail);
				SetStatusMessage();
				me[0].disabled = false;
			},
			success : function(data)
			{
				setTimeout(CheckHandleCollect, 10 * 1000);
			}
		});
	}
}

function CheckHandleCollect()
{
	$.ajax(
	{
		url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=IsRunning",
		data : {},
		type : "POST",
		error : function(request)
		{
			Alert(_lang_operation_fail);
		},
		success : function(data)
		{
			if (data.toLowerCase() == "true")
			{
				setTimeout(CheckHandleCollect, 10 * 1000);
			}
			else
			{
				SetStatusMessage();
				$("#HandleCollect")[0].disabled = false;
			}
		}
	});
}
//End : 栏目设置
//-------------------------------------------------

function Init()
{
	if (typeof (_page) == "undefined")
		return;
	
	if (_page == "company_list")
	{
		MakeButton();
		
		$("#IsRecycled,#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		$("#SelectAll").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = true;});});
		$("#ReverseSelect").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = !this.checked;});});
		
		//行业和地区联动
		$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx", Search);}); 
		$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx", Search);}); 
	}
	else if(_page == "company_add")
	{
		$("form:first").submit(AddCompany);
		$("[name=FoundedDate]").focus(function(){new DatePicker(this);});
		
		//行业和地区联动
		$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx");}); 
		$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx");}); 
	}
	else if(_page == "company_edit")
	{
		for (var i = 0; i < _tags.length; i++)
			$("[value=" + _tags[i] + "]")[0].checked = true;
		
		$("form:first").submit(EditCompany);
		$("[name=FoundedDate]").focus(function () { new DatePicker(this); });

		//地区联动
		BindLinkageRegion();
		if (_regionLinkageData.ID != "")
			LinkageSelect(_regionLinkageData);
		
		//行业联动
		BindLinkageIndustry();
		if (_industryLinkageData.ID != "")
			LinkageSelect(_industryLinkageData);
	}
	else if (_page == "company_replace")
	{
		_xmlDoc = CreateXmlDom();

		$("form").submit(ReplaceCompany);
		$("[name=Property]").change(Property_OnChange);
	}
	else if (_page == "person_list")
	{
		MakeButton();
		
		$("#IsRecycled,#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		$("#SelectAll").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = true;});});
		$("#ReverseSelect").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = !this.checked;});});
		
		//行业和地区联动
		$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx", Search);}); 
		$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx", Search);}); 
	}
	else if(_page == "person_add")
	{
		$("form:first").submit(AddPerson);
		$("[name=Birthday]").focus(function(){new DatePicker(this);});
		
		//行业和地区联动
		$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx");}); 
		$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx");}); 
	}
	else if(_page == "person_edit")
	{
		for (var i = 0; i < _tags.length; i++)
			$("[value=" + _tags[i] + "]")[0].checked = true;
		
		$("form:first").submit(EditPerson);
		$("[name=Birthday]").focus(function () { new DatePicker(this); });

		//地区联动
		BindLinkageRegion();
		if (_regionLinkageData.ID != "")
			LinkageSelect(_regionLinkageData);
		
		//行业联动
		BindLinkageIndustry();
		if (_industryLinkageData.ID != "")
			LinkageSelect(_industryLinkageData);
	}
	else if (_page == "mail_list")
	{
		MakeButton();
		
		$("#IsRecycled,#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		
		//行业和地区联动
		$("#Industry").delegate("select", "change", function(){Linkage(this, "../industry/ajax_json.aspx", Search);}); 
		$("#Region").delegate("select", "change", function(){Linkage(this, "../region/ajax_json.aspx", Search);}); 
	}
	else if(_page == "mail_add")
	{
		//月份改变时，调整日期
		$("[name=Month]").change(function()
		{
			$("[name=Date] [value=1]").attr("selected", true);
			var lastDate = new Date($("[name=Year]").val(), this.value, 0);
			
			var last = lastDate.getDate();
			$("[name=Date] option").each(function()
			{
				if (parseInt(this.value) > last)
					this.disabled = true;
				else
					this.disabled = false;
			});
		});

		//开始时间
		var now = new Date();
		$("[name=Month]").val(now.getMonth());
		$("[name=Date]").val(now.getDate());
		$("[name=Hour]").val(now.getHours());
		$("[name=Minute]").val(now.getMinutes());
		
		$("form:first").submit(AddMail);

		//行业和地区联动
		BindLinkageIndustry();
		BindLinkageRegion();
		
		$("[name=Every]").change(function()
		{
			if (this.value == "")
				$("#StartTimeTR").hide();
			else
				$("#StartTimeTR").show();
			
			if (this.value == "Week")
				$("#Day").show();
			else
				$("#Day").hide();
		});
		
		$("[name=Year]").blur(function()
		{
			if (!this.value.match(/^\d{4}$/) || parseInt(this.value) < now.getFullYear())
				this.value = now.getFullYear();
		});
	}
	else if(_page == "mail_edit")
	{
		//月份改变时，调整日期
		$("[name=Month]").change(function()
		{
			$("[name=Date] [value=1]").attr("selected", true);
			var lastDate = new Date($("[name=Year]").val(), this.value, 0);
			
			var last = lastDate.getDate();
			$("[name=Date] option").each(function()
			{
				if (parseInt(this.value) > last)
					this.disabled = true;
				else
					this.disabled = false;
			});
		});
		
		//发送方式
		$("[name=Every]").val(_every);

		//开始时间
		var startTime = new Date(_startTime);
		$("[name=Year]").val(startTime.getFullYear());
		$("[name=Month]").val(startTime.getMonth());
		$("[name=Date]").val(startTime.getDate());
		$("[name=Hour]").val(startTime.getHours());
		$("[name=Minute]").val(startTime.getMinutes());
		if (_every != "")
			$("#StartTimeTR").show();
		
		$("form:first").submit(EditMail);
		$("#Now").click(function(){$("[name=EndTime]").val(FormatDate(new Date(), "YYYY-MM-DD hh:mm:ss"));return false;});
		
		//地区联动
		BindLinkageRegion();
		if (_regionLinkageData.ID != "" && _regionLinkageData.ID != g_empty)
			LinkageSelect(_regionLinkageData);
		
		//行业联动
		BindLinkageIndustry();
		if (_industryLinkageData.ID != "" && _industryLinkageData.ID != g_empty)
			LinkageSelect(_industryLinkageData);
		
		$("[name=Every]").change(function()
		{
			if (this.value == "")
				$("#StartTimeTR").hide();
			else
				$("#StartTimeTR").show();
			
			if (this.value == "Week")
				$("#Day").show();
			else
				$("#Day").hide();
		});
		
		$("[name=Year]").blur(function()
		{
			var now = new Date();
			if (!this.value.match(/^\d{4}$/) || parseInt(this.value) < now.getFullYear())
				this.value = now.getFullYear();
		});
	}
	else if(_page == "mail_log_list")
	{
		if (_isRunning == "True")
		{
			$("#StartExecute")[0].disabled = true;
			SetStatusMessage(_lang_start_working);
			setTimeout(RefreshMailLog, _interval);
		}
		
		$("#IsSuccess,#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		$("#SelectAll").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = true;});});
		$("#ReverseSelect").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = !this.checked;});});
		$("#StartExecute").click(StartExecute);
		$(document.body).delegate("#StopExecute", "click", StopExecute);
	}
	else if (_page == "mail_sender_list")
	{
		MakeButton();
		
		var list = $("#List");
		list.delegate("[sort]", "mouseover", function(){this.className += " Move_MouseOver";});
		list.delegate("[sort]", "mouseout", function(){this.className="Move";});

		$("#IsRecycled,#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		$("#SelectAll").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = true;});});
		$("#ReverseSelect").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = !this.checked;});});
		$("#AutoSort").click(AutoSort);
		
		InitMove(null,"Move", null, MoveMailSender);
	}
	else if(_page == "mail_sender_add")
	{
		$("form:first").submit(AddMailSender);
	}
	else if(_page == "mail_sender_edit")
	{
		$("form:first").submit(EditMailSender);
	}
	else if (_page == "region_add")
	{
		$("form").submit(AddRegion);
		$("#GuidCheckBox").click(function()
		{
			this.form.ID.disabled = !this.checked;
			if (this.form.ID.disabled)
				this.form.ID.className = "Disabled";
			else
				this.form.ID.className = "Text";
		});
		
		//地区联动
		BindLinkageRegion();
	}
	else if (_page == "region_edit")
	{
		$("form").submit(EditRegion);
		$("#GuidCheckBox").click(function()
		{
			this.form.ID.disabled = !this.checked;
			if (this.form.ID.disabled)
				this.form.ID.className = "Disabled";
			else
				this.form.ID.className = "Text";
		});
		
		//地区联动
		BindLinkageRegion();
		if (_regionLinkageData.ID != "")
			LinkageSelect(_regionLinkageData);
	}
	else if (_page == "region_list")
	{
		var list = $("table");

		list.delegate("form", "submit", function()
		{
			var id = $(this).closest("tr").attr("ItemID");
			ModifyRegion(this, id);
			return false;
		});
		
		list.delegate("[sort]", "mouseover", function(){this.className += " Move_MouseOver";});
		list.delegate("[sort]", "mouseout", function(){this.className="Move";});
		
		list.delegate("td:last-child a", "click", function()
		{
			var id = $(this).closest("tr").attr("ItemID");
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)DeleteRegion(id);}, this);
			return false;
		});
		
		InitMove(null,"Move", null, MoveRegion);
	}
	else if (_page == "industry_add")
	{
		$("form").submit(AddIndustry);
		$("#GuidCheckBox").click(function()
		{
			this.form.ID.disabled = !this.checked;
			if (this.form.ID.disabled)
				this.form.ID.className = "Disabled";
			else
				this.form.ID.className = "Text";
		});

		//行业联动
		BindLinkageIndustry();
	}
	else if (_page == "industry_edit")
	{
		$("form").submit(EditIndustry);
		$("#GuidCheckBox").click(function()
		{
			this.form.ID.disabled = !this.checked;
			if (this.form.ID.disabled)
				this.form.ID.className = "Disabled";
			else
				this.form.ID.className = "Text";
		});
		
		//行业联动
		BindLinkageIndustry();
		if (_industryLinkageData.ID != "")
			LinkageSelect(_industryLinkageData);
	}
	else if (_page == "industry_list")
	{
		var list = $("table");

		list.delegate("form", "submit", function()
		{
			var id = $(this).closest("tr").attr("ItemID");
			ModifyIndustry(this, id);
			return false;
		});
		
		list.delegate("[sort]", "mouseover", function(){this.className += " Move_MouseOver";});
		list.delegate("[sort]", "mouseout", function(){this.className="Move";});
		
		list.delegate("td:last-child a", "click", function()
		{
			var id = $(this).closest("tr").attr("ItemID");
			Confirm(_lang_confirm_delete, function(returnValue){if (returnValue)DeleteIndustry(id);}, this);
			return false;
		});
		
		InitMove(null,"Move", null, MoveIndustry);
	}
	if (_page == "tag_list")
	{
		$("#List").delegate("form", "submit", function()
		{
			var id = $(this).attr("action");
			ModifyTag(this, id);
			return false;
		});

		$("#Sort").change(Search);
		$("#Keyword").keydown(function(e){if(e.keyCode == 13){Search(1);e.preventDefault();}});
		$("#Search").click(function(){Search(1);});
		$("#SelectAll").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = true;});});
		$("#ReverseSelect").click(function(){$(":checkbox[name=Sel]").each(function(){this.checked = !this.checked;});});
		$("#Delete").click(function(){DeleteTag();});
	}
	else if (_page == "tag_add")
	{
		$("form").submit(AddTag);
	}
	else if (_page == "tag_edit")
	{
		$("form").submit(EditTag);
	}
	else if (_page == "config_basic")
	{
		//月份改变时，调整日期
		$("[name=Month]").change(function()
		{
			$("[name=Date] [value=1]").attr("selected", true);
			var lastDate = new Date($("[name=Year]").val(), this.value, 0);
			
			var last = lastDate.getDate();
			$("[name=Date] option").each(function()
			{
				if (parseInt(this.value) > last)
					this.disabled = true;
				else
					this.disabled = false;
			});
		});
		
		$("[name=Year]").blur(function()
		{
			var now = new Date();
			if (!this.value.match(/^\d{4}$/) || parseInt(this.value) < now.getFullYear())
				this.value = now.getFullYear();
		});

		//开始时间
		var checkTime = new Date(_checkTime);
		$("[name=Year]").val(checkTime.getFullYear());
		$("[name=Month]").val(checkTime.getMonth());
		$("[name=Date]").val(checkTime.getDate());
		$("[name=Hour]").val(checkTime.getHours());
		$("[name=Minute]").val(checkTime.getMinutes());
		if ($("#EnableCheckYes")[0].checked)
			$("#CheckTime").show();

		$("form:first").submit(SetBasicSettings);
		$("#SyncIndustry").click(SyncIndustry);
		$("#SyncRegion").click(SyncRegion);
		$("#HandleCollect").click(HandleCollect);
		
		$("[name=EnableCheck]").click(function()
		{
			if (this.id == "EnableCheckYes")
				$("#CheckTime").show();
			else
				$("#CheckTime").hide();
		});

		if (_isRunning == "True")
		{
			$("#HandleCollect")[0].disabled = true;
			SetStatusMessage(_lang_start_working);
		}
		$(document.body).delegate("#Stop", "click", function()
		{
			SetStatusMessage(_lang_working);
		
			$.ajax(
			{
				url : _webPath + "alicms.aspx?Lang=" + _lang + "&Object=Company&Operation=Stop",
				data : {},
				type : "POST",
				error : function(request)
				{
					Alert(_lang_operation_fail);
					SetStatusMessage();
					$("#HandleCollect")[0].disabled = false;
				},
				success : function(data)
				{
					SetStatusMessage();
					$("#HandleCollect")[0].disabled = false;
				}
			});
		});
	}
}

Init();